package net.digitalartwork.mp3player {
	import flash.display.*;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.utils.*;
	import flash.events.*;
	import flash.text.*;
	import flash.events.MouseEvent;
	//--------------------------------------------------------------------------
	import gs.TweenFilterLite;
	import gs.OverwriteManager;
	import gs.easing.*;
	//--------------------------------------------------------------------------
	
	public class ProgressBar extends MovieClip {
		//--------------------------------------------------------------------------
		// ASSETS
		//--------------------------------------------------------------------------
		public var bg:MovieClip;
		public var progress_mc:MovieClip;
		public var loadprogress_mc:MovieClip;
		public var bounds_mc:MovieClip;
		public var visualizer_mc:MovieClip;
		//--------------------------------------------------------------------------
		// DISPATCH
		//--------------------------------------------------------------------------
		public var MOUSECLICK:String = "mousedown";
		public var ON_SCRUB:String = "onscrub";
		public var ON_SCRUB_DONE:String = "onscrubdone";

		//--------------------------------------------------------------------------
		// PROPERTIES
		//--------------------------------------------------------------------------
		public var _w:Number;
		public var _h:Number;
		public var _dragging:Boolean = false;
		public var _percent:Number = 0;
		//--------------------------------------------------------------------------
		public function ProgressBar() {
			trace("ProgressBar Init");
			//--------------------------------------------------------------------------
			visualizer_mc = new MovieClip;
			addChild(visualizer_mc);
			//--------------------------------------------------------------------------
			// 
			//--------------------------------------------------------------------------
			visualizer_mc.mouseEnabled = false;
			visualizer_mc.mouseChildren = false;
			bounds_mc.alpha = 0;
			
			progress_mc.mouseEnabled = false;
			progress_mc.mouseChildren = false;
			
			bg.mouseEnabled = false;
			bg.mouseChildren = false;
			
			bounds_mc.mouseEnabled = false;
			bounds_mc.mouseChildren = false;
			//--------------------------------------------------------------------------
			// 
			//--------------------------------------------------------------------------
			
			loadprogress_mc.buttonMode = true; 
			loadprogress_mc.useHandCursor = true;
			
			loadprogress_mc.addEventListener(MouseEvent.ROLL_OVER, onRollOverHandler); 
			loadprogress_mc.addEventListener(MouseEvent.ROLL_OUT, onRollOutHandler); 

			loadprogress_mc.addEventListener(MouseEvent.MOUSE_DOWN, onMouseStateDown); 
			loadprogress_mc.addEventListener(MouseEvent.MOUSE_UP, onMouseStateUp); 
			

			//--------------------------------------------------------------------------
			// Init States
			//--------------------------------------------------------------------------
			_w = bg.width;
			_h = bg.height;
			
			loadprogress_mc.width = 0;
			progress_mc.width = 0;
			
		}
		
		private function onRollOverHandler(e:MouseEvent):void {
			
		}
		
		private function onRollOutHandler(e:MouseEvent):void {
			if (_dragging) {
				loadprogress_mc.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseStateMove); 
				_dragging = false;
				dispatchEvent(new Event(ON_SCRUB_DONE));
			}
		}
		
		private function onClickHandler(e:MouseEvent):void {
			dispatchEvent(new Event(MOUSECLICK));

		}
		
		private function onMouseStateDown(e:MouseEvent):void {
			loadprogress_mc.addEventListener(MouseEvent.MOUSE_MOVE, onMouseStateMove); 
			_dragging = true;
			progress_mc.width = mouseX;
			_percent = (progress_mc.width / 100);
			dispatchEvent(new Event(ON_SCRUB));
		}
		
		private function onMouseStateUp(e:MouseEvent):void {
			if (_dragging) {
				loadprogress_mc.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseStateMove); 
				_dragging = false;
				dispatchEvent(new Event(ON_SCRUB_DONE));
			}
		}
		
		private function onMouseStateMove(e:MouseEvent):void {
			progress_mc.width = mouseX;
			_percent = (progress_mc.width / 100);
			dispatchEvent(new Event(ON_SCRUB));
		}
		
	}
	
}